package com.ntschy.bt.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ntschy.bt.entity.dataobject.BtDeclare;
import com.ntschy.bt.mapper.BtDeclareMapper;
import com.ntschy.bt.service.IBtDeclareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *     专项申报 服务实现类
 * </p>
 *
 * @author ymj
 * @since 2021-01-05
 */
@Service
public class BtDeclareServiceImpl implements IBtDeclareService {

    @Autowired
    private BtDeclareMapper declareMapper;

    // * ================================================基础增删改查BEGIN============================================= *

    /**
     * 分页查询申报列表
     * @param declare 专项申报对象
     * @return 申报列表
     */
    @Override
    public List<BtDeclare> pageDeclare(BtDeclare declare) {
        return declareMapper.pageDeclare(declare);
    }

    /**
     * 新增申报列表
     * @param declare 申报列表对象
     * @return 新增结果
     */
    @Override
    public int addDeclare(BtDeclare declare) {
        declare.setId(IdUtil.fastUUID());
        return declareMapper.insert(declare);
    }

    /**
     * 更新专项申报
     * @param declare 专项申报对象
     * @return 更新结果
     */
    @Override
    public int updateDeclare(BtDeclare declare) {
        return declareMapper.updateById(declare);
    }

    /**
     * 删除专项申报
     * @param id 专项申报ID
     * @return 删除结果
     */
    @Override
    public int deleteDeclare(String id) {
        return declareMapper.deleteById(id);
    }




    // * =================================================基础增删改查END============================================== *

    /**
     * 检查申报标题是否存在
     * @param title 申报标题
     * @return 校验结果
     */
    @Override
    public boolean checkExistTitle(String title) {
        return declareMapper.selectCount(new QueryWrapper<BtDeclare>().lambda().eq(BtDeclare::getTitle,title))>0;
    }



    /**
     * 根据id查询申报详情
     * @param id
     * @return
     */
    @Override
    public BtDeclare selectById(String id) {
        return declareMapper.selectById(id);
    }

}
